package com.zzl.study.demo.dao;

import com.zzl.study.demo.domain.Poem;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 诗词数据仓库
 *
 * @author: zhangzl
 * @date: 2025/10/13 15:19
 * @version: 1.0
 */
@Repository
public interface PoemRepository extends JpaRepository<Poem, Integer> {

    /**
     * 根据作者查询诗词列表
     *
     * @param author   作者名称
     * @param pageable 分页参数
     * @return 诗词列表
     */
    @Query("SELECT p FROM Poem p WHERE p.author = :author")
    List<Poem> findPoemsByAuthor(@Param("author") String author, Pageable pageable);

    /**
     * 根据标签查询诗词列表
     *
     * @param tag      标签名称
     * @param pageable 分页参数
     * @return 诗词列表
     */
    @Query("SELECT p FROM Poem p WHERE p.tags LIKE %:tag%")
    List<Poem> findPoemsByTag(@Param("tag") String tag, Pageable pageable);

}
